package com.example.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhxy.config.Result;
import com.example.zhxy.model.Grade;
import com.example.zhxy.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * ClassName: GradeController
 * Package: com.example.zhxy.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-02-14
 * Time: 13:30
 */

@RestController
@RequestMapping("/sms/gradeController")
public class GradeController {

    @Autowired
    private GradeService gradeService;


    //GET
    //	http://localhost:9001/sms/gradeController/getGrades/1/3?gradeName=
    // 年级的分页查询
    @GetMapping("/getGrades/{pageNo}/{pageSize}")
    public Result getGrades(@PathVariable("pageNo") Integer pageNo,
                            @PathVariable("pageSize") Integer pageSize,
                            String gradeName){
        //参数分别是 页码数 和 页大小
        //分页查询

        //  1. 设置分页信息 Page对象  分页构造器
        Page<Grade> page1 = new Page<>(pageNo,pageSize);
        // 通过调用服务层 设置分页信息 和 查询条件
        IPage<Grade> iPage = gradeService.getGradeOpr(page1,gradeName);

        return Result.ok(iPage);

    }
}
